package com.xja.controller;/**
 * @className: UserController
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/17
 **/


import com.xja.pojo.BlogUsers;
import com.xja.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @ClassName : UserController  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/17  20:19
 */
@Controller
@RequestMapping("user")
public class UserController {
    private Logger logger = LoggerFactory.getLogger(UserController.class);
    @Reference(url = "dubbo://localhost:20881")
    private UserService userService;

    @RequestMapping("toUser")
    public String toUser(Model model, @RequestParam(value = "page",defaultValue = "1") Integer page, BlogUsers users){
        logger.info("用户管理界面");
        List<BlogUsers> userList = userService.getUser(users, page);
        model.addAttribute("userList",userList);
        model.addAttribute("users",users);
        return "user";
    }

    @RequestMapping("freeze")
    public String freeze(Integer uid){
        logger.info("冻结用户");
        System.out.println(uid);
        userService.freezeUser(uid);
        return "redirect:/user/toUser";
    }

    @RequestMapping("active")
    public String active(Integer uid){
        logger.info("解冻用户");

        userService.activeUser(uid);

        return "redirect:/user/toUser";
    }
}
